﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MonitorCode;
using YouShuCode;

namespace DevSupport.Areas.Monitor
{
    [ApiController]
    public class ChartDataController : ControllerBase
    {
        private ILogger<ChartDataController> _logger;

        public ChartDataController(ILogger<ChartDataController> logger)
        {
            _logger = logger;
        }
        /// <summary>
        /// NPS 数据监控
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("api/Monitor/NpsData")]
        public object NpsData(int range = 7)
        {

            var dateNow = DateTime.Now.Date;

            var nameList = new List<string>();

            var numList = new List<string>();

            for (int i = range -1; i >=0; i--)
            {
                var ddd = dateNow.AddDays(-i);
               var _list = JobTest.JobDatas.Where(c=> c.SysDate.Value == ddd).ToList();
                nameList.Add(dateNow.AddDays(-i).Formatted("yyyy/MM/dd"));
                numList.Add(_list.Count().ToString());
            } 

            return new { names = nameList,nums=numList };
        }
        /// <summary>
        /// PinkCar 数据监控
        /// </summary>
        /// <param name="range"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("api/Monitor/PinkcarData")]
        public object PinkcarData(int range = 7)
        { 
            var dateNow = DateTime.Now.Date; 
            var nameList = new List<string>(); 
            var numList = new List<string>();

            for (int i = range - 1; i >= 0; i--)
            {
                var ddd = dateNow.AddDays(-i);
                var _list = JobTest.JobDatas.Where(c => c.SysDate.Value == ddd).ToList();
                nameList.Add(dateNow.AddDays(-i).Formatted("yyyy/MM/dd"));
                numList.Add(_list.Count().ToString());
            } 
            return new { names = nameList, nums = numList };
        }
    }
}
